package com.darksider.darkotlin.extras

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import android.support.v4.app.Fragment
import android.util.Log
import android.view.View
import com.darksider.darkotlin.settings.Settings.DEBUG

/**
 * User: yaodong(1126220529@qq.com)
 * Date: 2017-05-26
 * Time: 10:49
 * Description:日志扩展类 context扩展类 跳转扩展方法
 * Update:DEBUG开关移动到Settings
 */
fun Any.log_v(message: String) {
    if (DEBUG)
        Log.v(this::javaClass.name, message)
}

fun Any.log_d(message: String) {
    if (DEBUG)
        Log.d(this.javaClass.simpleName, message)
}

fun Any.log_i(message: String) {
    if (DEBUG)
        Log.i(this.javaClass.simpleName, message)
}

fun Any.log_w(message: String) {
    if (DEBUG)
        Log.w(this.javaClass.simpleName, message)
}

fun Any.log_e(message: String) {
    if (DEBUG)
        Log.e(this.javaClass.simpleName, message)
}
/*----------------------------------分割线----------------------------------*/

val View.ctx: Context
    get() = context

val Fragment.ctx: Context
    get() = context

val Activity.ctx: Context
    get() = this

val Activity.app: Application
    get() = application

/*----------------------------------分割线----------------------------------*/

inline fun <reified T : Activity> Activity.start(isFinish: Boolean = false) {
    startActivity(Intent(this, T::class.java))
    if (isFinish)
        this.finish()
}

